
$(function() {
	
	Tip.emp('出纳');
	
	$("select[id^='service_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
});

var BankMy = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.service = form.service.value;
				body.type = form.type.value;
				
				body.bank = form.bank.value;
				body.branch = form.branch.value;
				body.bankcode = form.bankcode.value;
				body.city = form.city.value;
				body.zone = form.zone.value;
								
				body.name = form.name.value;
				body.code = form.code.value;
				
				body.content = form.content.value;
				body.emp = form.emp.value;
	
				$(this).dialog("close");
				
				$.post('emp.php?do=BankMy.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	popup: function (e, p2, id) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var a1 = ['编辑信息', 'url', 'BankMy.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
		var a3 = ['复制信息', 'url', 'BankMy.dialog_copy_', '650x400'];
		
		var c1 = 'emp.php?do=BankMy.edit&id=' + id;
		var c2 = 'emp.php?do=BankMy.view&id=' + id;
		var c3 = 'emp.php?do=BankMy.copy&id=' + id;

		var s = c1 + ", " + c2 + ", " + c3;

		this.popup_(e, [a1, a2, a3], s);
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var ss = 'emp.php?do=BankMy.ss&id=' + id;
		var bb = ['修改状态', 'url', 'BankMy.dialog_ss', '400x200'];
		
		s += ", " + ss;
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BankMy.audit&item=147', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'emp.php?do=BankMy.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BankMy.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
						
						body.service = form.service.value;
						body.type = form.type.value;
						
						body.bank = form.bank.value;
						body.branch = form.branch.value;
						body.bankcode = form.bankcode.value;
						body.city = form.city.value;
						body.zone = form.zone.value;
						
						body.name = form.name.value;
						body.code = form.code.value;
						
						body.content = form.content.value;
						body.emp = form.emp.value;
						body.status = form.status.value;
			
						$(this).dialog("close");
			
						var url = 'emp.php?do=BankMy.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.service = form.service.value;
				body.type = form.type.value;
				
				body.bank = form.bank.value;
				body.branch = form.branch.value;
				body.bankcode = form.bankcode.value;
				body.city = form.city.value;
				body.zone = form.zone.value;
				
				body.name = form.name.value;
				body.code = form.code.value;
				
				body.content = form.content.value;
				body.emp = form.emp.value;
	
				$(this).dialog("close");
				
				$.post('emp.php?do=BankMy.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	}
};
